package com.g1.controller;

import com.g1.entity.Admin;
import com.g1.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("/login")
    public String login(Admin admin, HttpSession session){
        Admin loginAdmin = adminService.login(admin);
        if(loginAdmin!=null){
            session.setAttribute("user",admin);
        }else{
            return "redirect:/login.jsp?error=账号密码错误";
        }
        return "redirect:/studentList";
    }
}
